<?php

namespace App\Http\Controllers\Client\Shop\Goods;

use App\Http\Controllers\ClientController;
use App\Models\Tools\AliOss;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GoodsDetailController extends ClientController
{
    /**
     * 查询霸王餐活动策略详情
     */
    public function index()
    {
        try {
            $all = $this->all;
            $goods_id = $all['goods_id'];

            $result = DB::table('lottery_goods')
                ->where('goods_id', '=', $goods_id)
                ->first();
            $result = json_decode(json_encode($result), true);
            $result['title_img'] = AliOss::getUrl($result['title_img']);
            $goods_img = explode(',', $result['goods_img']);
            $result['goods_img'] = AliOss::getUrls($goods_img);

            // 查询活动，如果此活动有使用过，就不允许修改
            $in_used = DB::table('lottery_activity')->where('goods_id','=',$goods_id)->count();
            $result['in_used'] = $in_used && true;

            return $this->setReturnJson(0,'success',$result);
        } catch (\Exception $e){
            Log::error(GoodsDetailController::class,['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'查询失败');
        }
    }

}
